package xyz.wanwanwan.www.hrm.receiver;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import xyz.wanwanwan.www.hrm.config.RabbitmqConfig;

import java.io.IOException;

@Component
public class ReceiveMessage {
    @RabbitListener(queues= RabbitmqConfig.QUEUE_INFORM_SMS)
    public void receiveSMS(String msg, Message message, Channel channel) throws IOException {
        System.out.println("这是一条短信:"+msg);
        System.out.println("内容"+message.getBody());
        System.out.println("ReceivedExchange:"+message.getMessageProperties().getReceivedExchange());
        System.out.println("getDeliveryTag:"+message.getMessageProperties().getDeliveryTag());
        //只能占有一条信息发送
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
    @RabbitListener(queues = RabbitmqConfig.QUEUE_INFORM_EMAIL)
    public void receiveEmail(String msg, Message message, Channel channel) throws IOException {
        System.out.println("这是一封邮件:"+msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
